import http from "@/api";
import { Api } from "@/api/interface/api";

/**
 * @description 获取列表
 */
export const getApiList = (params?: Api.IApiParams) => {
  return http.Get<Api.TApiListResult>("/api/list", { params: { ...params } });
};

/**
 * @description 获取详情
 * @param {number} id id
 */
export const getApiDetail = (id: number) => {
  return http.Get<Api.TApiDetailResult>(`/api/detail/${id}`);
};

/**
 * @description 新增
 * @method post
 * @returns
 */
export const addApi = (data: Api.IApi) => {
  return http.Post("/api/add", data);
};

/**
 * @description 编辑
 * @method post
 * @returns
 */
export const editApi = (data: Api.IApi) => {
  return http.Post("/api/edit", data);
};

/**
 * @description 删除
 * @param {number} id 用户id
 * @method delete
 * @returns
 */
export const deleteApi = (id: number) => {
  return http.Delete(`/api/remove/${id}`);
};

/**
 * @description 获取分组列表
 */
export const getApiGroup = () => {
  return http.Get<Api.TApiGroupResult>("/api/group");
};

/**
 * 同步api列表
 */
export const syncApi = () => {
  return http.Get<Api.TApiSyncResult>("/api/synchronous");
};

/**
 *更新缓存
 */
export const updateApiCache = () => {
  return http.Get("/api/freshCasbin");
};

/**
 * 忽略接口
 */
export const ignoreApi = (data: Api.IApi) => {
  return http.Post("/api/ignore", data);
};

/**
 * 批量创建接口
 */
export const batchCreateApi = (data: Api.IApi[]) => {
  return http.Post("/api/batch-apis", data);
};
